package com.csust.zerocode.core.saver;

import com.csust.zerocode.ai.model.HtmlCodeResult;
import com.csust.zerocode.ai.model.MultiFileCodeResult;
import com.csust.zerocode.exception.BusinessException;
import com.csust.zerocode.exception.ErrorCode;
import com.csust.zerocode.model.enums.CodeGenTypeEnum;

import java.io.File;


/**
 * @ ClassName MultiFileCodeParser
 * @ Description  代码文件保存执行器  根据代码生成类型执行相应的保存逻辑
 * @ Author 钰玟
 * @ Date 2025/9/11 上午10:21
 * Version 1.0
 **/
public class CodeFileSaverExecutor {

    private static final HtmlCodeFileSaverTemplate htmlCodeFileSaver = new HtmlCodeFileSaverTemplate();

    private static final MultiFileCodeFileSaverTemplate multiFileCodeFileSaver = new MultiFileCodeFileSaverTemplate();

    /**
     * 执行代码保存
     *
     * @param codeResult  代码结果对象
     * @param codeGenType 代码生成类型
     * @return 保存的目录
     */
    public static File executeSaver(Object codeResult, CodeGenTypeEnum codeGenType,Long appId) {
        return switch (codeGenType) {
            case HTML -> htmlCodeFileSaver.saveCode((HtmlCodeResult) codeResult,appId);
            case MULTI_FILE -> multiFileCodeFileSaver.saveCode((MultiFileCodeResult) codeResult,appId);
            default -> throw new BusinessException(ErrorCode.SYSTEM_ERROR, "不支持的代码生成类型: " + codeGenType);
        };
    }
}
